<?php
include("config.php");

$addsql= "1";
if(isset($_REQUEST['act'])){
	if($_REQUEST['act'] == 'search'){
		$orderid = $_REQUEST['orderid'];
		$from = $_REQUEST['from'];
		$to = $_REQUEST['to'];
		
		if($orderid) 	$addsql .= " and order_id = '" .$orderid." '";
		if($from) 		$addsql .= " and order_time >= '" .$from." 00:00:00" . "'";
		if($to) 		$addsql .= " and order_time <= '" .$to." 59:59:59". "'";
	}
}else{
	if(isset($_REQUEST['type'])){
		$type = $_REQUEST['type'];
		$addsql = "status = $type";
	}
	
	$from = date("Y-m-d", time() - 3600*24*3);
	$to = date("Y-m-d");
	$orderid = '';
}
//'0=未发货，1=电话已确认，2=电话不通，3=取消订购，4=已退货, 5=其它原因'
$sql = "select * from orders where $addsql";
$ret = $mysql->query($sql);
$orderinfo = $mysql->fetch_array($ret);
$page = new page(array('total' => count($orderinfo), 'perpage' => 3));

//print_r('<pre>');print_r($orderinfo);
?>

<HTML>
<HEAD>
<TITLE>淘宝小赢家-订单系统</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<link rel="stylesheet" href="images/FONT.css" type="text/css">
<SCRIPT language=javascript src="jquery-1.2.1.pack.js"></SCRIPT>
</head>
<body text="#000000">
<table width="1000px" border="0" cellspacing="0" cellpadding="0" align="center" class="orderlist">
  <tr bgcolor="#4296E7"> 
      <td height="28" colspan="10" bgcolor="#CCCCCC"  colspan="9">
	  <table width="100%" background="memberimg/menu_bg.gif" border="0" cellspacing="0" cellpadding="0" align="center">
		<tr>
		  <td height="35" valign="bottom">
		  <table border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td width="20">&nbsp;</td>
			  <td width="88" height="27" align="center" background="memberimg/menu_bg_on.gif">订单查询</td>
			</td>
			</tr>
		  </table>
        </tr>
      </table>
	  </td>
  </tr>
  <tr>
	<td colspan="9" style="font-size:9pt">
	<div style="padding:3px;width: 735px">		
		<form name="form1" method="post" action="orderlist.php" style="font-size:9pt">
		<input name="delall" type="button" id="delall" value="删除" style="font-size:9pt"> |
		<input type="hidden" name="act" value="search">
		订单号：<input name="orderid" type="text" id="orderid" value="<?php echo $orderid;?>" size="10" style="font-size:9pt">
		开始时间:<input name="from" type="text" id="from" value="<?php echo $from;?>" size="10" style="font-size:9pt">
		结束时间:<input name="to" type="text" id="to" value="<?php echo $to;?>" size="10" style="font-size:9pt">
		<input name="Submit" type="submit" id="Submit" value="查询" style="font-size:9pt">
		</form>
	</div>	
  </td>
  </tr>
  <tr bgcolor="#5EA5E6">
  <td width="5%" > 
      <div align="center"><font color="#FFFFFF"> <input type="checkbox" name="checkall" id="checkall" onclick="checkall()"></font></div>
    </td>
    <td width="5%" > 
      <div align="center"><font color="#FFFFFF"> 订单号</font></div>
    </td>
    <td width="5%" height="30" > 
      <div align="center"><font color="#FFFFFF">收货人</font></div>
    </td>
    <td width="34%" > 
      <div align="center"><font color="#FFFFFF">联系方式</font></div>
    </td>
    <td width="12%" > 
      <div align="center"><font color="#FFFFFF">订购产品</font></div>
    </td>
    <!--<td width="10%" ><font color="#FFFFFF">发货地址</font></td>-->
    <td width="7%" ><div align="center"><font color="#FFFFFF">订购日期</font></div></td>
    <td width="7%" > 
      <div align="center"><font color="#FFFFFF">状态</font></div>
    </td>
	 <td width="6%" > 
      <div align="center"><font color="#FFFFFF">操作</font></div>
    </td>
  </tr>
  <?php if($orderinfo):?>
  <?php foreach($orderinfo as $key => $val):?>
    <tr> 
    <td width="5%" align="center"><input type="checkbox" name="checks[]" value=<?php echo $val['id'];?>></td>
    <td width="7%" align="center"><?php echo $val['order_id'];?></td>
    <td width="7%" align="center"><?php echo $val['receiver_name'];?></td>
    <td width="25%" align="center"><?php echo $val['phone'];?></td>
    <td width="20%" align="center" ><?php echo mb_substr($val['good_name'], 0, 45);?></td>
    <!--<td width="10%" align="center" ><?php echo $val['address'];?></td>-->
    <td width="10%" align="center" ><?php echo substr($val['order_time'],0,10);?></td>
    <td width="10%" align="center" ><b>
		<?php
			$s = $val['status'];
			echo $good_status[$s];
		?>
		</b>
	</td>
    <td width="10%" align="center" >
		<a href="orderview.php?id=<?php echo $val['id'];?>"><b style="color:#09C">详情</b></a>&nbsp;
		<a href="orderlist.php?act=del&id=<?php echo $val['id'];?>" onclick="return confirm('确定要删除吗？');">删除</a>&nbsp;</td>
	</td>
  </tr>
  <?php endforeach;?>
  <?php else:?>
    <tr> 
    <td colspan="9" align="center">暂无订单！</td>
  </tr>
  <?php endif;?>
  
	
  <tr>
    <td height="1" colspan="10" align="right"><?php echo $page->show(7);?></td>
  </tr>	
  <tr>
    <td height="1" colspan="10" align="center" bgcolor="#f2f2f2"></td>
  </tr>
</table>

<script>
function checkall(){
	if($("input:checkbox[name='checkall']").attr("checked")){
		$("input:checkbox").attr("checked", true);
	}else{
		$("input:checkbox").attr("checked", false);
	}
}

$("#delall").click(function(){
	if(confirm("你确定删除吗？")){
		var ids = [];
		$("input:checkbox[checked]").each(function(){
			ids.push($(this).val());
		});
		
		$.get("ajax.php?ids=" + ids.join(',') , function(xx){
			console.log(xx);
			alert("删除完成！");
			location.href = "orderlist.php";
		});
	}
});
</script>

</body>
</html>